#include "Shader.hpp"
#include <iostream>

Shader::Shader(const char* vertexSource, const char* fragmentSource)
{
	program = CreateShader(vertexSource, fragmentSource);
}

void Shader::UseNoShader()
{
	glUseProgram(0);
}

bool Shader::Use() const
{
	if(program != 0)
	{
		glUseProgram(program);
		return true;
	}

	return false;
}

//const Shader Shader::PassthroughShader("Shaders/PassthroughVertex.glsl", "Shaders/PassthroughFragment.glsl");
Shader* Shader::PassthroughShader;
Shader* Shader::PhongShader;
Shader* Shader::HorizontalGauss;
Shader* Shader::VerticalGauss;
Shader* Shader::BlendShader;
Shader* Shader::PassthroughShaderPost;
Shader* Shader::SimpleHorizGauss;
Shader* Shader::SimpleVertGauss;

void Init()
{
	Shader::PassthroughShader = new Shader("Shaders/PassthroughVertex.glsl", "Shaders/PassthroughFragment.glsl");
	Shader::PassthroughShaderPost = new Shader("Shaders/PassthroughVertex.glsl", "Shaders/PassthroughFragmentPost.glsl");
	Shader::PhongShader = new Shader("Shaders/SimpleVertex.glsl", "Shaders/SimpleFrag.glsl");
	Shader::HorizontalGauss = new Shader("Shaders/PostVertex.glsl", "Shaders/HorizontalGaussFrag.glsl");
	Shader::VerticalGauss = new Shader("Shaders/PostVertex.glsl", "Shaders/VerticalGaussFrag.glsl");
	Shader::BlendShader = new Shader("Shaders/PassthroughVertex.glsl", "Shaders/BlendShader.glsl");
	
	Shader::SimpleHorizGauss = new Shader("Shaders/PostVertex.glsl", "Shaders/SimpleHorizGaussFrag.glsl");
	Shader::SimpleVertGauss = new Shader("Shaders/PostVertex.glsl", "Shaders/SimpleVertGaussFrag.glsl");
}



void Shader::UpdateUniform(const char* VariableName, float value)
{
	Use();
	GLint loc = glGetUniformLocation(GetProgram(), VariableName);
	if(loc == -1)
	{
		std::cout << "Uniform " << VariableName << " not found." << std::endl;
	}
	glUniform1fv(loc, 1, &value);
}
